#include <iostream>
#include <string>
#include <queue>
using namespace std;

struct Node {
	string val;
	Node* left = nullptr;
	Node* right = nullptr;
};
string sp;
Node* H = nullptr;
void getTree(Node*& h)
{
	string cur;
	cin >> cur;
	if (cur == sp) return;
	h = new Node;
	h->val = cur;
	getTree(h->left);
	getTree(h->right);
}
bool jug(Node* h)
{
	if (!h) return true;
	queue<Node*> q;
	q.push(h);
	while (q.size()) {
		int k = q.size();
		while (k--) {
			auto e = q.front(); q.pop();
			if (!e) {
				while (q.size()) {
					if (q.front()) return false;
					q.pop();
				}
			}
			else {
				q.push(e->left);
				q.push(e->right);
			}
		}
	}
	return true;
}
int main()
{
	cin >> sp;
	getTree(H);
	if (jug(H)) cout << "true";
	else cout << "false";
	return 0;
}